#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

ll qmi(ll a, ll b)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)res = res * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return res;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> pre(n + 1);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        pre[i + 1] = pre[i] + a[i];
    }
    int q;
    cin >> q;

    while(q--)
    {
        int l1, u;
   
        
        cin >> l1 >> u;
        int l = l1, r = n;
        while(l < r)
        {    
            int mid = (l + r + 1) >> 1;
            auto check = [&](int m)
            {
                int t = pre[mid] - pre[l1 - 1];
                return t <= (u - 1);
            };            
            if(check(mid)) l = mid;
            else r = mid - 1; 

        }
        int x = pre[l] - pre[l - 1];
        int  t = u - x;
        if(t > (a[l + 1] + 1) / 2)
            l++;
        cout << l << ' ';
    }
    cout << endl;
}

int main()
{
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}